/**
 *  @author Morozan Ion
 *  
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.dddforandroid.application;
 
import java.util.Date;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

import com.dddforandroid.api.R;
import com.dddforandroid.api.SQLiteBackup;

public class ClientAPIActivity extends Activity {

	public final static String AUTH = "authentication";

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		SQLiteBackup sql = new SQLiteBackup();

		/**
		 * authentication and initialize sql database and create a database
		 * based on preferences. C2dm registration.
		 */
		sql.initializeDB(Andrus.class, ClientAPIActivity.this);
 
		/** adding data to server - POST */ 
		String[] id = new String[3];
		for (int i = 0; i < 3; i++) {
			id[i] = sql.insertObject(new Andrus("ObjectName" + i, "ObjectNote"
					+ i, new Date(), "ToDo" + i), ClientAPIActivity.this);
		}
		Log.v("AddingServer - POST", "Success");

		/** Reading data from Content Provider */
		String readData = sql.readSQLDatabase();

		/** Reading data from server - GET */
		String readServer = sql.readServerDatabase();
		Log.v("ReadServer - GET", "Successfully getting data from server!");

		/** Modify object - PUT */
		boolean modified = sql.modifyObject(new Andrus("ObjectName100",
				"ObjectNote100", new Date(), "ToDo100"),
				ClientAPIActivity.this, id[0]);
		Log.v("ModifyServer - PUT",  "Data successfully updated");

		/** Delete object from database - DELETE */
		boolean deleted = sql.deleteObject(new Andrus("ObjectName2",
				"ObjectNote2", new Date(), "ToDo2"), ClientAPIActivity.this,
				id[1]);
		Log.v("DeleteServer - DELETE", "Data successfully deteled!");

	}
}